package com.ocean.greedy.easy;

/**
 * <Description> <br>
 *
 * @author linmiaolai@sanyygp.com<br>
 * @version 1.0<br>
 * @date 2023/02/20 <br>
 */
public class CanPlaceFlowers {

    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        if (n == 0) {
            return true;
        }
        for (int i = 0; i < flowerbed.length; ++i) {
            if (flowerbed[i] == 0 && (i + 1 == flowerbed.length || flowerbed[i + 1] == 0)) {
                n--;
                i++;
            } else if (flowerbed[i] == 1) {
                i++;
            }
            if (n <= 0) {
                break;
            }
        }
        return n <= 0;
    }
}
